package com.sgb.goods.viewmodel;

import androidx.databinding.ObservableBoolean;
import androidx.databinding.ObservableField;

import com.sgb.goods.api.GoodsCallBack;
import com.sgb.goods.api.GoodsNet;
import com.sgb.goods.entity.InvoiceDetailsEntity;
import com.sgb.goods.utils.base.viewmodel.BaseViewModel;
import com.sgb.goods.view.adapter.InvoiceDetailsAdapter;
import com.swgk.core.base.model.entity.BaseEntity;

/**
 * 发票详情
 * @author cyj
 */
public class InvoiceDetailsViewModel extends BaseViewModel {

    public InvoiceDetailsAdapter adapter;
    public ObservableField<InvoiceDetailsEntity> detailsData = new ObservableField<>();
    public ObservableBoolean isShowInvoiceList = new ObservableBoolean(false);

    public InvoiceDetailsViewModel() {
        adapter = new InvoiceDetailsAdapter();
    }

    /** 获取开票详情 */
    public void getInvoiceDetails(String orderId) {
        showLoading();
        GoodsNet.getInstance().getGoodsApi().getTradingContractContent(orderId).enqueue(new GoodsCallBack<BaseEntity<InvoiceDetailsEntity>>() {
            @Override
            public void onSuccess(BaseEntity<InvoiceDetailsEntity> data) {
                if(null != data.getData().invoice) {
                    adapter.setNewData(data.getData().invoice);
                    isShowInvoiceList.set(adapter.getItemCount() > 0);
                }
                detailsData.set(data.getData());
            }
        });
    }
}
